<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>音频</title>
</head>
<body>
<video src="" id="video"></video>
<script>
    // Prefer camera resolution nearest to 1280x720.
    // var constraints = { audio: true, video: { width: 1280, height: 720 } };

    var constraints = { audio: true, video: { width: 100, height: 100 } }
    navigator.mediaDevices.getUserMedia(constraints)
        .then(function(mediaStream) {
            var video = document.querySelector('video');
            video.srcObject = mediaStream;
            console.log(mediaStream)
            video.onloadedmetadata = function(e) {
                video.play();
            }
        })
        .catch(function(err) { console.log(err.name + ": " + err.message); }); // always check for errors at the end.
</script>
</body>
</html>
